﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatchParseRegexContent
    {
        public int Add(KeRui.Model.CmsCatchParseRegexContent model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@ParseContentID", SqlDbType.Int, 4), new SqlParameter("@FieldName", SqlDbType.VarChar, 50), new SqlParameter("@Pattern", SqlDbType.NVarChar), new SqlParameter("@Replacement", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime) };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.ParseContentID;
            parameters[2].Value = model.FieldName;
            parameters[3].Value = model.Pattern;
            parameters[4].Value = model.Replacement;
            parameters[5].Value = model.CreateTime;
            DbHelperSQL.RunProcedure("CmsCatchParseRegexContent_ADD", parameters, out num);
            return (int) parameters[0].Value;
        }

        public void Delete(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            DbHelperSQL.RunProcedure("CmsCatchParseRegexContent_Delete", parameters, out num);
        }

        public bool Exists(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            return (DbHelperSQL.RunProcedure("CmsCatchParseRegexContent_Exists", parameters, out num) == 1);
        }

        public KeRui.Model.CmsCatchParseRegexContent GetModel(int ID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            KeRui.Model.CmsCatchParseRegexContent content = new KeRui.Model.CmsCatchParseRegexContent();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatchParseRegexContent_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    content.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString());
                }
                if (set.Tables[0].Rows[0]["ParseContentID"].ToString() != "")
                {
                    content.ParseContentID = int.Parse(set.Tables[0].Rows[0]["ParseContentID"].ToString());
                }
                content.FieldName = set.Tables[0].Rows[0]["FieldName"].ToString();
                content.Pattern = set.Tables[0].Rows[0]["Pattern"].ToString();
                content.Replacement = set.Tables[0].Rows[0]["Replacement"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    content.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return content;
            }
            return null;
        }

        public void Update(KeRui.Model.CmsCatchParseRegexContent model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@ParseContentID", SqlDbType.Int, 4), new SqlParameter("@FieldName", SqlDbType.VarChar, 50), new SqlParameter("@Pattern", SqlDbType.NVarChar), new SqlParameter("@Replacement", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime) };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.ParseContentID;
            parameters[2].Value = model.FieldName;
            parameters[3].Value = model.Pattern;
            parameters[4].Value = model.Replacement;
            parameters[5].Value = model.CreateTime;
            DbHelperSQL.RunProcedure("CmsCatchParseRegexContent_Update", parameters, out num);
        }
    }
}

